/**
 * 
 */
package cn.ivicar.redis.pubsub;

/**
 * @author liurunbin 2017年7月9日 cn.ivicar.redis.pubsub
 */
public class RedisPubSubFactory {

	private static RedisConsumer consumer;

	private static String CONSUMER_LOCK = "CONSUMER_LOCK";

	public static RedisConsumer subscribe(String channel, MessageHander hander) {

		if (consumer == null) {
			synchronized (CONSUMER_LOCK) {
				if (consumer == null) {
					consumer = new RedisConsumer(channel, hander);
				}
			}

		}

		if (!consumer.isOpened()) {
			synchronized (CONSUMER_LOCK) {
				if (!consumer.isOpened()) {
					consumer.open();
				}
			}
		}

		return consumer;

	}
}
